#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#include <ctime>
#define ldb double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1 << 30;
const ldb pi = fabsl(atan2(0.0, -1.0));
using namespace std;
 
int n, m;
int edges, first[510], end[5000], next[5000], beg[5000];
ldb cost[5000];
ldb d[1010], f[1010];
int p[1010];
 
 
void addEdge(int i, int j, ldb cst)
{
	next[edges] = first[i];
	beg[edges] = i;
	first[i] = edges;
	end[edges] = j;
	cost[edges] = cst;
	edges++;
}
int was[5011];
int st[5011];


void dfs(int ver)
{
	was[ver] = 1;
	for (int u = first[ver]; u != -1; u = next[u])
	{
		if (was[end[u]]) continue;
		dfs(end[u]);
	}
}
 
 
void Load()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
		f[i] = 0.5 - f[i];
	}
	edges = 0;
	for (int i = 0; i <= n; i++) first[i] = -1, was[i] = 0;
	int j, k;
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", &j, &k);
		addEdge(j, k, f[j]);
		addEdge(k, j, f[k]);
	}
	root = n;
	for (int i = 0; i < n; i++)
	{
		if (was[i]) continue;
		addEdge(root, i, 0);
		dfs(i);
	}
}
 
void out(int i)
{
	int sz = 0;
	while (was[i] == 0)
	{
		was[i] = sz + 1;
		st[sz++] = i;
		i = beg[p[i]];
	}
	for (int k = was[i] - 1; k < sz; k++)
		printf("%d ", st[k]);
	printf("-1");
	for (; sz; sz--)
	{
		was[st[sz - 1]] = 0;
	}
}

bool used[10000];
 
void out2(int i)
{
	int sz = 0;
	while (was[i] == 0)
	{
		was[i] = sz + 1;
		used[p[i] / 2] ^= 1;
		st[sz++] = i;
		if (i % 2 == 0)
			i = beg[p[i]] * 2 + 1;
		else i = beg[p[i]] * 2;
	}
	for (i = 0; i < m; i++)
	{
		if (used[i])
		{
			go(i)
		}
	}
	for (; sz; sz--)
		was[st[sz - 1]] = 0;
}
 
bool findOddCycle(int nver)
{
	int i, j;
	f[nver] -= 0.5;
	for (i = 0; i < 2 * n; i++)
		d[i] = 1e42;
	d[nver * 2] = 0;
	p[nver * 2] = nver * 2;
	for (i = 0; i <= 2 * n; i++)
	{
		for (j = 0; j < edges; j++)
		{
			if (d[beg[j] * 2] < 1e42 - eps && d[end[j] * 2 + 1] > d[beg[j] * 2] + f[beg[j]] + eps)
			{
				d[end[j] * 2 + 1] = d[beg[j] * 2] + f[beg[j]];
				p[end[j] * 2 + 1] = j;
				if (end[j] == nver && d[nver * 2 + 1] < -eps)
				{
					printf("Bad Cycle: ");
					out(beg[j] * 2);
					printf("\n");
					return true;
				}
				
			}
			if (d[beg[j] * 2 + 1] < 1e42 - eps && end[j] != nver && d[end[j] * 2] > d[beg[j] * 2 + 1] + f[beg[j]] + eps)
			{
				d[end[j] * 2] = d[beg[j] * 2 + 1] + f[beg[j]];
			//	cerr << end[j] << " " << 0 << " from " << beg[j] << " " << d[end[j] * 2] << "\n";
				p[end[j] * 2] = j;
			}
		}
	}
	f[nver] += 0.5;
	return false;
}
 
	
void Solve()
{
	int i, j;
	for (i = 0; i <= n; i++)
	{
		d[i] = 1e42;
		was[i] = 0;
	}
	d[root] = 0;
	p[root] = root;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < edges; j++)
		{
			if (d[beg[j]] < INF - eps && d[end[j]] > d[beg[j]] + cost[j] + eps)
			{
				d[end[j]] = d[beg[j]] + cost[j];
				p[end[j]] = j;
			}
		}
	}
	for (j = 0; j < edges; j++)
	{
		if (d[beg[j]] < 1e42 - eps && d[end[j]] > d[beg[j]] + cost[j] + eps)
		{
			printf("Bad Cycle: ");
			out(beg[j]);
			printf("\n");
			return;
		}
	}
	for (int i = 0; i < 50; i++)
	{
		int t = rand() % n;
		if (findOddCycle(t))
			return;
	}
	printf("Ok\n");
}
 
#define file "genind"
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	#endif
	int T;
	cin >> T;
	srand(time(0));
	int i;
	for (i = 0; i < T; i++)
	{
		Load();
		Solve();
	}
	return 0;
}
 